package com.profound.blog.service;

import java.sql.SQLException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Service;

import com.profound.blog.bean.RegUser;
import com.profound.blog.dao.RegUserDAO;

@Service
public class RegUserService {

	@Autowired
	private RegUserDAO dao;
	
	public RegUser logon(String regName,String pwd){
		return this.dao.logon(regName, pwd);
	}
	
	public boolean regist(String regName,String pwd, String email, String question, String answer){
		
		boolean ok = false;
		RegUser u = new RegUser(null, regName, pwd, email, question, answer, null, null, null,
				null, null, null, null, null, null, null, null, null, null, null, null,null);
		if(null!=this.dao.add(u)){
			ok = true;
		}	
		return ok ;
	}
	
	public boolean validateRegName(String regName){
		int count = -1;
		boolean ok = false;
		count = this.dao.findByName(regName);
		if(count==0){
			ok = true;
		}
		return ok;
	}

	public boolean validateEmail(String email){
		int count = -1;
		boolean ok = false;
		count = this.dao.findByEmail(email);
		if(count==0){
			ok = true;
		}
		return ok;
	}
	
	public boolean updatePersonInfo(RegUser u){
		boolean ok = false;
		if(1==this.dao.update(u)){
			ok = true;
		}
		return ok;
	}

	public boolean updatePersonSafety(RegUser u){
		boolean ok = false;
		if(1==this.dao.updateSafety(u)){
			ok = true;
		}
		return ok;
	}
}
